package com.gewu.pm.ui.activity.home;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.viewpager.widget.ViewPager;

import com.androidkun.xtablayout.XTabLayout;
import com.gewu.pm.R;
import com.gewu.pm.app.AppActivity;
import com.gewu.pm.app.AppFragment;
import com.gewu.pm.bean.ClockInStatisticsBean;
import com.gewu.pm.ui.fragment.home.DailySummaryFragment;
import com.gewu.pm.ui.fragment.home.MonthlySummaryFragment;
import com.gewu.pm.widget.CircularProgressView;
import com.hjq.base.FragmentPagerAdapter;

/**
 * 打卡报表
 */
public final class ReportClockInActivity extends AppActivity {

    private CircularProgressView mCircularProgress;
    private XTabLayout mTabLayout;
    private ViewPager mViewPager;
    private FragmentPagerAdapter<AppFragment<?>> mPagerAdapter;

    public static void start(Context context) {
        Intent intent = new Intent(context, ReportClockInActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_report_clock_in;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        mCircularProgress = findViewById(R.id.cpv_progress);
        mTabLayout = findViewById(R.id.tab_layout);
        mViewPager = findViewById(R.id.vp_content);

    }

    @Override
    protected void initData() {
        mPagerAdapter = new FragmentPagerAdapter<>(this);
        mPagerAdapter.addFragment(DailySummaryFragment.newInstance(), "每日汇总");
        mPagerAdapter.addFragment(MonthlySummaryFragment.newInstance(), "月度汇总");
        mViewPager.setAdapter(mPagerAdapter);

        // 关联XTabLayout和ViewPager
        mTabLayout.setupWithViewPager(mViewPager);

        // 加载测试数据
        loadTestData();
    }

    @Override
    public void onRightClick(View view) {
        super.onRightClick(view);
        // 点击标题重新绘制圆形进度圈（带动画效果）
        if (mCircularProgress != null) {
            mCircularProgress.redrawWithAnimation();
            toast("重新绘制进度圈");
        }
    }

    /**
     * 加载测试数据
     */
    private void loadTestData() {
        // 创建测试数据并设置到圆形进度图
        ClockInStatisticsBean statistics = new ClockInStatisticsBean();
        statistics.setLateCount(3);// 迟到人数
        statistics.setEarlyLeaveCount(3);// 早退人数
        statistics.setAbsentCount(2);// 旷工人数

        // 设置圆形进度图数据
        mCircularProgress.setStatisticsData(statistics);
    }

}
